//
// Created by 17775 on 2024/6/21.
//

#ifndef RAYCI_BEAMRESULTS_H
#define RAYCI_BEAMRESULTS_H

#include <QWidget>
#include <QDockWidget>
#include <QTreeWidgetItem>
#include "../RayCi/LiveMode.h"
#include "../LiveMode/LiveMode_Analysis.h"

QT_BEGIN_NAMESPACE
namespace Ui { class BeamResults; }
QT_END_NAMESPACE

//class LiveMode;
using DataVariant = std::variant<double, QString>;

class BeamResults : public QDockWidget {
Q_OBJECT

signals:
    void stopNewResultThread();

public slots:
    void getNewStatistic(StatisticResult statisticResult);
    void getNewThreshold(StatisticResult statisticResult, ThresholdResult thresholdResult);
    void getNewSecondMoments(StatisticResult statisticResult, SecondMomentsResult secondMomentsResult);
    void getNewGauss(StatisticResult statisticResult, GaussResult gaussResult);
    void getNewSuperGauss(StatisticResult statisticResult, GaussResult gaussResult);
    void getNewPlateau(StatisticResult statisticResult, PlateauResult plateauResult);
    void getNewSimpleGeometry(StatisticResult statisticResult, SimpleGeometry simpleGeometry);
    void getNewKnifeEdge(StatisticResult statisticResult, KnifeEdge knifeEdge);
    void getNewMovingSlit(StatisticResult statisticResult, KnifeEdge knifeEdge);
    void getNewDropdown(StatisticResult statisticResult, KnifeEdge knifeEdge);

public:
    explicit BeamResults(QWidget *parent = nullptr);
    ~BeamResults() override;
    void setWindowTitleName(const QString& name);

    void closeBeamResults();
    void changeView(MethodsType method,bool bGaussSigma, int sigmaIndex, int thresholdIndex, int fractionIndex);
    void changeThresholdValue(MethodsType method, int index);
    void changeSigmaEnvironment(MethodsType method, int index);
    void changeFraction(MethodsType method, int index);
    void changeSigma(int sigmaIndex);
    void changeThreshold(int thresholdIndex);
    void powerFractionChanged(int fractionIndex);
    void changeSlope(MethodsType method, bool slopeIsChecked);
    void changeUnit(QString unit);
    void closeEvent(QCloseEvent *event) override;
    void hidePowerProfileItem(bool bShow);
    void updatePowerProfileItem(double dDiameter = 0.0000, double dPowerContent = 0.00);
    void updatePowerPositionItem(double dDiameter = 0.0000);
    void updatePowerContentItem(double dPowerContent = 0.00);

private:
    Ui::BeamResults *ui;

    void initView();
    QTreeWidgetItem* oneTop = nullptr;
    QTreeWidgetItem* firstChildItem = nullptr;
    QTreeWidgetItem* secChildItem = nullptr;
    QTreeWidgetItem* thrChildItem = nullptr;
    QTreeWidgetItem* fourChildItem = nullptr;
    QTreeWidgetItem *fiveChildItem = nullptr;
    QTreeWidgetItem *sixChildItem = nullptr;
    QTreeWidgetItem *svnChildItem = nullptr;
    QTreeWidgetItem* twoTop = nullptr;
    QTreeWidgetItem* twoTopItem = nullptr;
    QTreeWidgetItem* twoTopChildItem = nullptr;
    QTreeWidgetItem* twoTopSecChildItem = nullptr;
    QTreeWidgetItem* twoTopThrChildItem = nullptr;
    QTreeWidgetItem* twoTopFourChildItem = nullptr;
    QTreeWidgetItem* twoTopFiveChildItem = nullptr;
    QTreeWidgetItem* twoTopSixChildItem = nullptr;
    QTreeWidgetItem* twoTopSvnChildItem = nullptr;
    QTreeWidgetItem* twoTopEiChildItem = nullptr;
    QTreeWidgetItem* twoTopNineChildItem = nullptr;
    QTreeWidgetItem* twoTopTenChildItem = nullptr;
    QTreeWidgetItem* twoTopEleChildItem = nullptr;
    QTreeWidgetItem* twoTopTweChildItem = nullptr;
    QTreeWidgetItem* twoTopThirteenChildItem = nullptr;
    QTreeWidgetItem* twoTopFourteenChildItem = nullptr;
    QTreeWidgetItem* twoTopFifteenChildItem = nullptr;
    QTreeWidgetItem* twoTopSixteenChildItem = nullptr;
    QTreeWidgetItem* twoTopSeventeenChildItem = nullptr;
    QTreeWidgetItem* twoTopEighteenChildItem = nullptr;
    QTreeWidgetItem* twoTopNineteenChildItem = nullptr;
    QTreeWidgetItem* twoTopThirtyChildItem = nullptr;

    QTreeWidgetItem* twoTopTwentyChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentyOneChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentyTwoChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentyThrChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentyFourChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentyFiveChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentySixChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentySevenChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentyEightChildItem = nullptr;
    QTreeWidgetItem* twoTopTwentyNineChildItem = nullptr;

    QTreeWidgetItem* powerProfileTop = nullptr;
    QTreeWidgetItem* powerProfileTopItem = nullptr;
    QTreeWidgetItem* powerProfileDiameterItem = nullptr;
    QTreeWidgetItem* powerProfilePowerContentItem = nullptr;
};


#endif //RAYCI_BEAMRESULTS_H
